﻿Imports UCBase

Public Class ImageStreamer
    Implements I_LoadSave
    Private WithEvents SourceEvent As I_ImageExchange

    Private Loader As New WebUploader("http://www.extremesurvival.co.za/ucs/Submit.php")
    Private M_Busy As Boolean = False
    Private fc As Integer = 0
    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        If TextBox1.Text > "" Then Loader.StreamName = TextBox1.Text
    End Sub
    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
        If TextBox2.Text > "" Then Loader.UserName = TextBox2.Text
    End Sub
    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
        If TextBox3.Text > "" Then Loader.Password = TextBox3.Text
    End Sub
    Private Sub SocketIn_Connect() Handles SocketIn.Connect
        Dim S As Socket = SocketIn.Remote
        SourceEvent = S.Parent
    End Sub

    Private Sub SourceEvent_ImageOut1(ByVal Image As System.Drawing.Bitmap) Handles SourceEvent.ImageOut1
        If CheckBox3D1.Checked Then
            If M_Busy = True Then Exit Sub
            M_Busy = True
            Led1.State = Led.LedState.Led_On
            Dim bmp As New Bitmap(Image.Width, Image.Height + 20, Imaging.PixelFormat.Format32bppRgb)
            Dim G As Graphics = Graphics.FromImage(bmp)
            G.Clear(Color.Black)
            Dim D As Date = My.Computer.Clock.GmtTime
            G.DrawString(D.ToUniversalTime, Label4.Font, Brushes.White, 1, 1)
            G.DrawImage(Image, 0, 20)
            G.Dispose()
            Dim Num As String = Format(D, "yyyyMMdd_HHmmss_fff")
            Dim F As String = "c:\ucs\system\data\" & Loader.StreamName & "_" & Num & ".jpg"
            'Label4.Text = F
            bmp.Save(F, System.Drawing.Imaging.ImageFormat.Jpeg)
            bmp.Dispose()
            Dim R As Boolean = Loader.UploadFile(F)
            Led1.State = Led.LedState.Led_Off
            Timer1.Enabled = True
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer1.Enabled = False
        M_Busy = False

    End Sub

    Public Function GetSettings() As String Implements UCBase.I_LoadSave.GetSettings
        Return ""
    End Function

    Public Sub SetSettings(ByVal Settings As String) Implements UCBase.I_LoadSave.SetSettings

    End Sub

    Private Sub KnobControl1_ValueChanged(ByVal Sender As System.Object) Handles KnobControl1.ValueChanged
        Timer1.Interval = KnobControl1.Value * 1000
    End Sub
End Class
